#!/bin/bash
# tests for jevents
# may need executing event_download.py first to get event list for this cpu
set -e 
set -x

failed() {
        echo FAILED
}
trap failed ERR 0

PATH=.:./examples:$PATH


listevents > l
[ $(wc -l < l) -gt 50 ] 
grep -q offcore_response l

if grep -q br_misp_retired.taken l ; then
	E=br_misp_retired.taken
elif grep -q br_misp_retired.near_taken l ; then
	E=br_misp_retired.near_taken
else
	E=instructions
fi

jestat true
jestat -e cpu-cycles,cpu_clk_unhalted.ref_tsc,$E true
jestat -a sleep 1

showevent $E

event-rmap $E

examples/addr
examples/rtest
examples/rtest2

trap "" ERR 0

echo SUCCEEDED


